class SmsJob < ApplicationJob
  queue_as :default

  def perform(mobile, templateid, datas)
    conn = Faraday.new(url: $sms_host)
    timestamp = Time.now.strftime('%Y%m%d%H%M%S')
    conn.headers['Accept'] = 'application/json'
    conn.headers['Authorization'] = Base64.strict_encode64($sms_account + ':' + timestamp)
    conn.headers['Content-Type'] = 'application/json;charset=utf-8'
    conn.post "/2013-12-26/Accounts/#{$sms_account}/SMS/TemplateSMS?sig=#{Digest::MD5.hexdigest($sms_account + $sms_token + timestamp)}", {
        to: "#{mobile}",
        appId: $sms_app_id,
        templateId: templateid,
        datas: datas,
        data: ''
    }.to_json
  end
end
